import axios from 'axios';
import qs from 'qs';

const Axios = axios.create({
    baseURL: "http://localhost:9287"
})

export const get = function (action,params) {
    action = `${action}?${qs.stringify(params)}`
    return new Promise((resolve,reject) => {
        Axios.get(action)
        .then((res) => {
            const { code,data,msg } = res.data
            if(code == 200) {
                resolve(data)
            } else {
                reject(msg)
            }
        })
        .catch((error) => {
            reject(error)
            throw error;
        });
    })
}

export const post = function (action,params) {
    return new Promise((resolve,reject) => {
        Axios.post(action,{
            data:params
        }).then((res) => {
            const { code,data,msg } = res.data
            if(code == 200) {
                resolve(data)
            } else {
                reject(msg)
            }
        })
        .catch((error) => {
            reject(error)
            throw error;
        })
    }) 
}  